import db from '../db/index.js'
export function stuleave(req,res){
    const {studentid,teacherid,reson,end_time,postion,phone,person,phones}=req.body
    const sql = 'insert into leaves set studentid=?,teacherid=?,reson=?,end_time=?,postion=?,phone=?,person=?,phones=?,create_time=?'
    const time = new Date()
    db.query(sql,[studentid,teacherid,reson,end_time,postion,phone,person,phones,time],(err,data)=>{
        if(err) return res.dbno(err)
            res.send({status:200})
    })
}
export function getstuleave(req,res){
    const {studentid}=req.query
    const sql ='select studentid,reson,end_time,postion,phone,person,phones,create_time,isleave from leaves where studentid=?'
    db.query(sql,studentid,(err,data)=>{
        if(err) return res.dbno(err)
            res.send({status:200,leave:data})
    })
}
export function tecleave(req,res){
       const {id,tinfo,isleave}=req.body
       console.log(id,tinfo,isleave);
       
       const sql ='update leaves set tinfo=?,isleave=? where id = ?'
       db.query(sql,[tinfo,isleave,id],(err,data)=>{
          if(err) return res.dbno(err)
             res.send({status:200})
       })
}
export function gettecleave(req,res){
        const {teacherid}=req.query
    const sql ='select id,studentid,reson,end_time,postion,phone,person,phones,isleave from leaves where teacherid=?'
    db.query(sql,teacherid,(err,data)=>{
        if(err) return res.dbno(err)
            res.send({status:200,leave:data})
    })
}